import { getStore } from '@/utils/store'

export const tableConfig = () => {
	const userInfo = getStore('userInfo') || {}
	// 用户类型;1：大众用户，2：平台管理员，3：政务用户,4: 养老服务组织用户
	const classifyId = userInfo.classifyId

	const adminConfig = {
		stripe: true,
		border: true,
		maxHeight: '80vh',
		columns: [
			{
				label: '养老机构名称',
				prop: 'orgName',
			},
			{
				label: '名称',
				prop: 'subsidyProjectName',
			},
			{
				label: '归属区域',
				prop: 'areaName',
			},
			{
				label: '补贴年月',
				prop: 'belongDateLabel',
			},
			{
				label: '审批人',
				prop: 'approvalUser',
			},
			{
				label: '审批时间',
				prop: 'approvalTime',
			},
			{
				label: '补贴发放情况',
				prop: 'grantStatus',
				custome: 'tag',
				dicData: [
					{ label: '发放中', value: 0, style: { color: '#FF8800', background: '#FFDBB1' } },
					{ label: '已发放', value: 1, style: { color: '#00A870', background: 'rgba(0, 168, 112, 0.1)' } },
				],
			},
			{
				label: '发放时间',
				prop: 'grantDate',
			},
			// {
			// 	label: '是否上传补贴凭证',
			// 	prop: 'haRreceiptImgs',
			// },
			{
				label: '操作',
				prop: 'menu',
				width: 300,
				fixed: 'right',
			},
		],
	}
	const orgConfig = {
		stripe: true,
		border: true,
		maxHeight: '80vh',
		columns: [
			{
				label: '名称',
				prop: 'subsidyProjectName',
			},
			{
				label: '归属区域',
				prop: 'areaName',
			},
			{
				label: '补贴年月',
				prop: 'belongDateLabel',
			},
			{
				label: '审批人',
				prop: 'approvalUser',
			},
			{
				label: '审批时间',
				prop: 'approvalTime',
			},
			{
				label: '补贴发放情况',
				prop: 'grantStatus',
				custome: 'tag',
				dicData: [
					{ label: '发放中', value: 0, style: { color: '#FF8800', background: '#FFDBB1' } },
					{ label: '已发放', value: 1, style: { color: '#00A870', background: 'rgba(0, 168, 112, 0.1)' } },
				],
			},
			{
				label: '发放时间',
				prop: 'grantDate',
			},
			// {
			// 	label: '是否上传补贴凭证',
			// 	prop: 'haRreceiptImgs',
			// },
			{
				label: '操作',
				prop: 'menu',
				width: 120,
				fixed: 'right',
			},
		],
	}
	return classifyId == 2 || classifyId == 3 ? adminConfig : orgConfig
}

const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'right',
	column: [
		{
			label: '所属区域',
			prop: 'authAreas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '养老机构名称',
			prop: 'orgName',
			type: 'input',
			span: 8,
		},
		// {
		// 	label: '建设补贴类型',
		// 	prop: 'subsidyType',
		// 	type: 'remoteSelect',
		// 	span: 8,
		// 	api: 'getDictItemList',
		// 	code: 'SUBSIDY_TYPE',
		// },
		{
			label: '审批人',
			prop: 'approvalUser',
			type: 'input',
			span: 8,
		},
		{
			label: '审批时间',
			prop: 'approvalTimeBetween',
			type: 'dateBetween',
			span: 8,
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
		},
		{
			label: '补贴发放情况',
			prop: 'grantStatus',
			type: 'select',
			span: 8,
			dicData: [
				{
					label: '发放中',
					value: 0,
				},
				{
					label: '已发放',
					value: 1,
				},
			],
		},
	],
}

export const baseConfig: any = {
	pageName: '资金回执管理',
	dictcodes: [],
	rowKey: 'id',
	tipLabel: 'projectName',
	api: {
		index: 'view_ofsSubsidyApply_page',
		detail: 'view_ofsSubsidyApply_view',
	},
	auth: {
		index: 'view_ofsSubsidyApply_page',
		detail: 'view_ofsSubsidyApply_view',
	},
	paramsObj: {
		approvalStatusList: [3, 4, 5],
	},
	dialogConfig: {
		width: '50%',
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: 'view_ofsSubsidyApply_receipt',
			text: true,
			show: true,
		},
	],
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			item.haRreceiptImgs = item.receiptImgs ? '是' : '--'
			return {
				...item,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	searchConfig,
	tableConfig: tableConfig(),
}
